<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="__STATIC__/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="__STATIC__/css/font.css">
    <link rel="stylesheet" href="__STATIC__/css/xadmin.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" src="__STATIC__/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="__STATIC__/js/xadmin.js"></script>
</head>

<body class="layui-anim layui-anim-up">
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="">店铺管理</a>
        <a href="">
          <cite>厨师列表</cite>
        </a>
      </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">&#xe666;</i></a>
</div>
<div class="x-body">
    <div class="layui-row" style="text-align: center">
        <form class="layui-form layui-col-md12 x-so">
            <div class="layui-input-inline">
                <select name="shop_id" lay-filter="shop_id" lay-verify="required">
                    <option value="0">请选择店铺</option>
                    {volist name="data" id="vo"}
                    <option value="{$vo.id}">{$vo.shop_name}</option>
                    {/volist}
                </select>
            </div>
            <button class="layui-btn"  lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
        </form>
    </div>
    <xblock>
        <button class="layui-btn" onclick="x_admin_show('添加厨师','{:url("staff/cookAdd")}',460,600)"><i class="layui-icon"></i>添加</button>
    </xblock>
    <table id="table" lay-filter="test"></table>
    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-bg-blue layui-btn-xs" lay-event="confirm">修改</a>
        <a class="layui-btn layui-bg-blue layui-btn-xs" lay-event="del">删除</a>
    </script>
</div>
<script>
    layui.use(['form','laydate','table'], function(){
        var form = layui.form
            ,laydate = layui.laydate
            ,table = layui.table;
        laydate.render({
            elem: '#start' //指定元素
        });
        laydate.render({
            elem: '#end' //指定元素
        });
        form.on('submit(sreach)',function (data) {
            console.log(data);
            table.render({
                elem: '#table'
                ,url: '{:url("staff/cookData")}' //数据接口
                ,where:{
                    shop_id:data.field.shop_id
                }
                ,page: true //开启分页
                ,cols: [[ //表头
                    {field: 'id', title: 'ID' ,fixed: 'left'}
                    ,{field: 'true_name', title: '厨师姓名'}
                    ,{field: 'job_number', title: '工号'}
                    ,{field: 'phone', title: '手机号'}
                    ,{field: 'shop_id', title: '所属店铺'}
                    ,{field: 'staff_status', title: '状态',templet:function (d) {
                            if (d.staff_status == 1){
                                return '<span class="layui-btn layui-btn-normal layui-btn-xs">在职</span>';
                            } else {
                                return '<span class="layui-btn layui-btn-danger layui-btn-xs">离职</span>';
                            }
                        }}
                    ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:130}
                ]]
            });
            return false;
        });
        table.on('tool(test)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的DOM对象

            if(layEvent === 'confirm'){ //查看
                x_admin_show('厨师修改','{:url("staff/cookEdit")}?user_id='+data.id,460,600);
            } else if(layEvent === 'del'){ //删除
                layer.confirm('真的删除行么', function(index){
                    $.post('{:url("staff/cookDel")}',{id:data.id},function (res) {
                        if (res.code==1){
                            layer.msg(res.msg,{icon:6,time:1000},function () {
                                layer.close(index);
                                obj.del();
                            });
                        } else {
                            layer.msg(res.msg,{icon:5,time:1000},function () {
                                layer.close(index);
                            });
                        }
                    });
                });
            }
        });
    });

    /*用户-删除*/
    function member_del(obj,id){
        layer.confirm('确认要删除吗？',function(index){
            //发异步删除数据
            $(obj).parents("tr").remove();
            layer.msg('已删除!',{icon:1,time:1000});
        });
    }
</script>
</body>

</html>